package com.jcf.springboot.controller.business;


import com.jcf.springboot.common.R;
import com.jcf.springboot.entity.business.Director;
import com.jcf.springboot.service.DirectorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jjj
 * @since 2021-03-25
 */
@RestController
@CrossOrigin
@RequestMapping("/director")
public class DirectorController {

    @Autowired
    private DirectorService directorService;

    @GetMapping("getDirectorList")
    public R getDirectorList(){
        List<Director> list = directorService.list(null);
        if(list != null){
            return R.ok().data(list).message("获取导演列表成功");
        }
        else{
            return R.error().message("获取导演列表失败");
        }
    }

    @GetMapping("getDirectorById")
    public R getDirectorById(String id){
        Director director = directorService.getById(id);
        if(director != null){
            return R.ok().data(director).message("获取导演成功");
        }
        else{
            return R.error().message("获取导演失败");
        }
    }

    @GetMapping("getDirectorByFilmId")
    public R getDirectorByFilmId(String id){

        List<Director> director = directorService.getDirectorByFilmId(id);
        if(director != null){
            return R.ok().data(director).message("获取导演成功");
        }
        else{
            return R.error().message("获取导演失败");
        }
    }

    @PutMapping("editDirector")
    public R editDirector(@RequestBody Director director){
        boolean b = directorService.updateById(director);
        if(b){
            return R.ok().message("修改导演信息成功");
        }
        else{
            return R.error().message("修改导演信息失败");
        }
    }
}

